module.exports = ({ roleSchema, organizationSchema }) => ({
  PriUser: {
    roles: {
      fragment: `... on PriUser { roleIds }`,
      resolve (user, args, context, info) {
        return info.mergeInfo.delegateToSchema({
          schema: roleSchema,
          operation: 'query',
          fieldName: 'roles',
          args: {
            where: {
              _id: {
                $in: user.roleIds
              }
            },
            pagination: {
              limit: 10
            }
          },
          context,
          info
        })
      }
    },
    organizations: {
      fragment: `... on PriUser { organizationIds }`,
      resolve (user, args, context, info) {
        return info.mergeInfo.delegateToSchema({
          schema: organizationSchema,
          operation: 'query',
          fieldName: 'organizations',
          args: {
            where: {
              _id: {
                $in: user.organizationIds
              }
            },
            pagination: {
              limit: 10
            }
          },
          context,
          info
        })
      }
    }
  }
})
